home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / dejagnu.lha / dejagnu-1.0.1 / tcl / tests / while.test < prev   
Text File  |  1992-11-06  |  3KB  |  93 lines

  1. # Commands covered:  while
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright 1991 Regents of the University of California
  8. # Permission to use, copy, modify, and distribute this
  9. # software and its documentation for any purpose and without
  10. # fee is hereby granted, provided that this copyright notice
  11. # appears in all copies.  The University of California makes no
  12. # representations about the suitability of this software for any
  13. # purpose.  It is provided "as is" without express or implied
  14. # warranty.
  15. #
  16. # $Header: /sprite/src/lib/tcl/tests/RCS/while.test,v 1.5 91/09/08 13:43:30 ouster Exp $ (Berkeley)
  17.  
  18. if {[string compare test [info procs test]] == 1} then {source defs}
  19.  
  20. test while-1.1 {basic while loops} {
  21.     set count 0
  22.     while {$count < 10} {set count [expr $count+1]}
  23.     set count
  24. } 10
  25. test while-1.2 {basic while loops} {
  26.     set value xxx
  27.     while {2 > 3} {set value yyy}
  28.     set value
  29. } xxx
  30.  
  31. test while-2.1 {continue in while loop} {
  32.     set list {1 2 3 4 5}
  33.     set index 0
  34.     set result {}
  35.     while {$index < 5} {
  36.     if {$index == 2} {set index [expr $index+1]; continue}
  37.     set result [concat $result [lindex $list $index]]
  38.     set index [expr $index+1]
  39.     }
  40.     set result
  41. } {1 2 4 5}
  42.  
  43. test while-3.1 {break in while loop} {
  44.     set list {1 2 3 4 5}
  45.     set index 0
  46.     set result {}
  47.     while {$index < 5} {
  48.     if {$index == 3} break
  49.     set result [concat $result [lindex $list $index]]
  50.     set index [expr $index+1]
  51.     }
  52.     set result
  53. } {1 2 3}
  54.  
  55. test while-4.1 {errors in while loops} {
  56.     set err [catch {while} msg]
  57.     list $err $msg
  58. } {1 {wrong # args: should be "while test command"}}
  59. test while-4.2 {errors in while loops} {
  60.     set err [catch {while 1} msg]
  61.     list $err $msg
  62. } {1 {wrong # args: should be "while test command"}}
  63. test while-4.3 {errors in while loops} {
  64.     set err [catch {while 1 2 3} msg]
  65.     list $err $msg
  66. } {1 {wrong # args: should be "while test command"}}
  67. test while-4.4 {errors in while loops} {
  68.     set err [catch {while {"a"+"b"} {error "loop aborted"}} msg]
  69.     list $err $msg
  70. } {1 {can't use non-numeric string as operand of "+"}}
  71. test while-4.5 {errors in while loops} {
  72.     set x 1
  73.     set err [catch {while {$x} {set x foo}} msg]
  74.     list $err $msg
  75. } {1 {expression didn't have numeric value}}
  76. test while-4.6 {errors in while loops} {
  77.     set err [catch {while {1} {error "loop aborted"}} msg]
  78.     list $err $msg $errorInfo
  79. } {1 {loop aborted} {loop aborted
  80.     while executing
  81. "error "loop aborted""
  82.     ("while" body line 1)
  83.     invoked from within
  84. "while {1} {error "loop aborted"}"}}
  85.  
  86. test while-5.1 {while return result} {
  87.     while {0} {set a 400}
  88. } {}
  89. test while-5.2 {while return result} {
  90.     set x 1
  91.     while {$x} {set x 0}
  92. } {}
  93.